package com.wwj.study.zookeeper.lock;

import java.io.IOException;
import java.util.concurrent.CountDownLatch;

/**
 * @Author: wuweijun
 * @Date: 2019/1/11 15:02
 */
public class App {
    public static void main(String[] args) throws IOException {

        final CountDownLatch countDownLatch=new CountDownLatch(10);

        for (int i=0;i<10;i++) {
            Thread thread=new Thread(new Runnable() {
                public void run() {
                    try {
                        countDownLatch.await();
                        DistributedLock distributedLock=new DistributedLock();
                        distributedLock.lock();

                        Thread.sleep(2000);

                        distributedLock.unlock();

                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                }
            },"Thread-"+i);
            thread.start();
            countDownLatch.countDown();
        }

        System.in.read();
    }
}
